<?php
/**
 * Created by PhpStorm.
 * User: CYF
 * Date: 2018/1/28
 * Time: 5:32
 */

namespace Home\Model;
use Think\Model\BaseModel;

class CourseModel extends BaseModel{
    //教师权限
    protected $teachercourse;

    protected $_scope = array(
       'department' => array(
              //'where'=> array('dept_id'=>'012'),
              'field'=> array('cou_id','cou_name','cou_credit','cou_credithour'),
       ),
        'teacher' => array(
              'field'=> array('cou_id','cou_name'),
        )
    );
    protected $_map = array(
        'id' =>  'cou_id',
        'name' => 'cou_name',
        'par_id' => 'dept_id',
        'credit' => 'cou_credit',
        'hour' => 'cou_credithour'

    );


    public function getCourseInfoListByAll(){
        $result = $this->select();

        if($result){
            return $result;
        }else{
            return array();
        }
    }

    public function  getCourseInfoListByDepartment($dept_id){

        if ($dept_id == 0){
            $dept_id = array('like','%%');
        }

        $result = $this->scope('department',array('where'=> array('dept_id'=>$dept_id)))->select();
        if ($result){
            foreach ($result as $key => $value) {
                $result[$key]['type'] = '必修课';
            }

            return $result;
        }else{
            return array();
        }
    }
    public function  getCourseInfoListForTeacherNounByDepartment($dept_id,$teacher_id){

//        if ($dept_id == 0){
//            $dept_id = array('like','%%');
//        }

        $result = $this->scope('teacher',array('where'=> array('dept_id'=>$dept_id)))->select();

        if ($result){
            $this->teachercourse = D('teachercourse','Model');
            $noun_info = $this->teachercourse->getTeacherCourseNounInfoList($teacher_id);
            $data = array();
            $num = 0;
            foreach ($result as $key => $value){
                $flag = true;
                foreach ($noun_info as $noun_key => $noun_value){
                    if ($value['id'] == $noun_value['cou_id']){
                        $flag = false;
                        break;
                    }
                }
                if ($flag){
                    $data[$num++] = $value;
                }
            }
            return $data;
        }else{
            return array();
        }
    }



}